package com.teemor.blog.controller;

import com.teemor.blog.api.ISubscribeApiService;
import com.teemor.blog.bean.condition.TbSubscribeCondition;
import com.teemor.blog.bean.dto.input.subscribe.AddSubscribeIPo;
import com.teemor.blog.bean.dto.input.subscribe.QrySubscribesIPo;
import com.teemor.blog.bean.dto.input.subscribe.UpdSubscribeIPo;
import com.teemor.blog.bean.dto.output.subscribe.QrySubscribeOPo;
import com.teemor.blog.bean.dto.output.subscribe.QrySubscribesOPo;
import com.teemor.blog.bean.entity.TbSubscribe;
import com.teemor.blog.service.ISubscribeService;
import java.util.List;

import com.teemor.common.bean.utils.BeanConvertor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: zhoulk
 * @Description: 原子服务API接口实现
 * @date: 2020/03/24 17:33:32
 */
@RestController
public class SubscribeController implements ISubscribeApiService {
    @Autowired
    private ISubscribeService iSubscribeService;

    @Override
    public QrySubscribeOPo qrySubscribe(@PathVariable Integer id) {
        return BeanConvertor.convertBean(iSubscribeService.qrySubscribeById(id), QrySubscribeOPo.class);
    }

    @Override
    public int countSubscribe(@RequestBody QrySubscribesIPo inParam) {
        TbSubscribeCondition condition = BeanConvertor.convertBean(inParam, TbSubscribeCondition.class);
        return iSubscribeService.countSubscribe(condition);
    }

    @Override
    public List<QrySubscribesOPo> qrySubscribes(@RequestBody QrySubscribesIPo inParam) {
        TbSubscribeCondition condition = BeanConvertor.convertBean(inParam, TbSubscribeCondition.class);
        return BeanConvertor.convertBeanList(iSubscribeService.qrySubscribes(condition), QrySubscribesOPo.class);
    }

    @Override
    public void updSubscribe(@RequestBody UpdSubscribeIPo inParam) {
        TbSubscribe tbSubscribe = BeanConvertor.convertBean(inParam, TbSubscribe.class);
        iSubscribeService.updSubscribeById(tbSubscribe);
    }

    @Override
    public void addSubscribe(@RequestBody AddSubscribeIPo inParam) {
        TbSubscribe tbSubscribe = BeanConvertor.convertBean(inParam, TbSubscribe.class);
        iSubscribeService.addSubscribe(tbSubscribe);
    }
}